//
//  ViewController.m
//  TestStoryBoard
//
//  Created by 朱志佳 on 2019/4/4.
//  Copyright © 2019 朱志佳. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField1;
@property (weak, nonatomic) IBOutlet UITextField *textField2;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self test];
    
}

//总结如下：1. Storyboard中的First Responder只是一个placeholder，它不是具体指向哪个responder，2. 如果程序不在乎谁是First Responder，都让First Responder执行某个action（比如这里的paste:），那么我们就可以把event发给First Responder。

- (void)test {
    
    NSString *copyString = @"Hello Dev!";
    
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    
    [pasteboard setString:copyString];
    
    [_textField1 becomeFirstResponder];
    
    __weak typeof(self) weakSelf = self;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [weakSelf.textField1 paste:copyString];//成为第一响应者之后，才可以调用paset：方法并有效粘贴值
    });
    
}

- (IBAction)switchAndPaste:(id)sender {
    
    NSString *copyString = @"Hello Dev!";
    
    [_textField1 paste:copyString];//成为第一响应者之后，才可以调用paset：方法并有效粘贴值
    
}

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

-(IBAction)ExitFirst:(UIStoryboardSegue *)sender {
    NSLog(@"%@##%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
}

-(void)dealloc {
    NSLog(@"%@ dealloc",NSStringFromClass(self.class));
}

@end
